package com.share.dubbo.wssh.interceptor;


import com.share.dubbo.ssm.model.AccessLogSaveReq;
import com.share.dubbo.ssm.service.AccessLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
public class AccessLogInterceptor implements HandlerInterceptor {
    
    @Reference
    private AccessLogService accessLogService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        AccessLogSaveReq record = new AccessLogSaveReq();
        record.setHost(request.getRemoteAddr());
        record.setUrl(request.getRequestURI());
        accessLogService.insert(record);
        return true;
    }
}
